<template>
  <div class="my_contain">
    <vue-particles
      class="login-bg"
      color="#39AFFD"
      :particleOpacity="0.7"
      :particlesNumber="100"
      shapeType="circle"
      :particleSize="4"
      linesColor="#8DD1FE"
      :linesWidth="1"
      :lineLinked="true"
      :lineOpacity="0.4"
      :linesDistance="150"
      :moveSpeed="3"
      :hoverEffect="true"
      hoverMode="grab"
      :clickEffect="true"
      clickMode="push"
    >
    </vue-particles>
    <div class="contain_body">
      <div class="user_login">
        <div class="login_title">个人信息管理系统</div>
        <div class="login_form">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="demo-ruleForm" autocomplete="off">
            <el-form-item prop="username">
              <!-- <input type="text" style="display:none;"> -->
              <el-input prefix-icon="el-icon-user" v-model="ruleForm.username" autocomplete="off" placeholder="账号"></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <!-- <input type="text" style="display:none;"> -->
              <el-input prefix-icon="el-icon-lock" v-model="ruleForm.password" type="password" autocomplete="new-password" @keyup.enter.native="login('ruleForm')" placeholder="密码"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="login('ruleForm')" :loading="loading">立 即 登 录</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
    <div class="contain_footer">
      <div>dulily 版权所有 &copy;</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      loading: false,
      ruleForm: {
        username: '',
        password: '',
      },
      rules: {
        username: [
          { required: true, message: '请输入账号', trigger: 'blur' },
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
        ],
      }
    }
  },
  methods: {
    login(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          this.loading = true
          const res = await this.$store.dispatch('user/login', this.ruleForm)
          if (res.data.code === 200) {
            this.$notify.success('登录成功')
            this.$router.push('/index')
            this.loading = false
          } else {
            this.loading = false
          }
        } else {
          return false
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-button {
  width: 320px;
  background: rgba(49, 128, 183, 0.75);
  border: 1px solid rgba(27, 44, 56, 0.75);
}
::v-deep .el-input__inner {
  background-color: transparent !important;
  color: #fff;
}
.my_contain {
  background-color: #202632;
  width: 100%;
  height: 100%;
  color: #fff;
  position: relative;
  .login-bg {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 999;
  }
  .contain_body {
    width: 100%;
    height: calc(100% - 40px);
    display: flex;
    align-items: center;
    justify-content: center;
    .user_login {
      position: relative;
      z-index: 1200;
      width: 380px;
      height: auto;
      border: 1px solid rgba(69, 79, 100, 0.7);
      border-radius: 5px;
      background: rgba(50, 63, 90, 0.4);
      box-shadow: 0 0 1px 1px rgba(112, 132, 171, 0.4);
      .login_title {
        padding: 30px 30px 0 30px;
        font-size: 20px;
        text-align: center;
        letter-spacing: 2px;
      }
      .login_form {
        padding: 30px 30px 8px 30px;
      }
    }
  }
  .contain_footer {
    width: 100%;
    height: 40px;
    background: rgba(27,31,42,.5);
    color: #686b70;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    bottom: 0;
    left: 0;
  }
}
</style>